#!/bin/bash
#DSUB -n abinit_01
#DSUB --job_type cosched
#DSUB -N 1
#DSUB -R cpu=128;mem=496000;gpu=0
#DSUB -A root.account-hjc
#DSUB -q root.C
#DSUB -d "106-01:GRAPES" 
#DSUB -T "1h" 
#DSUB -l normal
#DSUB -o %J_out.log
#DSUB -e %J_err.log


export HOSTFILE=hostfile.gfs
rm -f $HOSTFILE
touch $HOSTFILE
`cat ${CCSCHEDULER_ALLOC_FILE} | sort | awk -v fff="$HOSTFILE" '{}
{
        split($0, a, " ")
        if (length(a[1]) >0 && length(a[3]) >0) {
                print a[1]" slots="128 >> fff
        }
}'`

echo "hmpi hostfile $HOSTFILE generated:"
echo "-----------------------"
cat $HOSTFILE
echo "-----------------------"

##配置环境变量
os=`cat /etc/os-release|grep VERSION_ID|awk -F \" '{print $2}'`
module use /share/home/top_software/sunqian/hpcrunner-old/software/modulefiles
module purge
#module load kgcc/9.3.1
module load bisheng/2.1.0
module load hmpi/1.1.1
if [ "$os" == "22.03" ] || [ "$os" == "V10" ] ;then
module load hdf5-clang/1.10.1  
module load pnetcdf/1.11.2   
module load netcdf-clang/4.7.4

else
module load hdf5/1.10.1  
module load pnetcdf/1.11.2 
module load netcdf/4.7.0
fi
module load openblas/0.3.18

cd /share/home/top_software/sunqian/abinit-8.10.3/tests/hpc
sed -i '6s/npband [0-9]*/npband 8/g' t01.in
sed -i '6s/npfft [0-9]*/npfft 8/g' t01.in

numcpu=1024
#dsub -n "abinit_01" -N 1 -A account-hjc -q root.default -R "cpu=32;mem=4096" -o out.log -e error.log "sleep 10"

echo "-----------------------"
echo $os
echo "-----------------------"

#time -p mpirun --allow-run-as-root -np $numcpu -hostfile $HOSTFILE --mca plm_rsh_agent -x OMP_NUM_THREADS=1 /share/home/top_software/sunqian/abinit-8.10.3/build/src/98_main/abinit < /share/home/top_software/sunqian/abinit-8.10.3/tests/hpc/hpc_x.files


time -p mpirun --allow-run-as-root -np 64 -hostfile $HOSTFILE -x OMP_NUM_THREADS=1 /share/home/top_software/sunqian/abinit-8.10.3/build/src/98_main/abinit < /share/home/top_software/sunqian/abinit-8.10.3/tests/hpc/hpc_x.files
